package com.douqu.game.core.config.map;

import com.douqu.game.core.e.E_CityDropBelong_Status;
import com.douqu.game.core.e.E_CityDropPower_Type;
import com.douqu.game.core.e.E_CityDrop_Flush_Type;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.util.time.TimeData;

/**
 * @author: miralce.
 * Description:
 * Date: 2018/7/4 0004 上午 11:19
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class CityDropGroupConfig extends GameObject {

    public int type;

    public String subtype;
    /** 情景条件 */
    public int killSubType;
    /**
     * 时间类型,不序列化
     */
    public transient TimeData timeSubType;

    /** 刷在什么势力*/
    public int locateType;

    /** 玩家归属可见 */
    public int visibleType;

    /** 持续时间 */
    public int aliveTime;

    /** 数量 */
    public int count;

    /** 组 */
    public int rewardGroupId;

    /** 提示语 */
    public String localization;

    @Override
    public boolean check() {
        //指定时间刷新
        if (type == E_CityDrop_Flush_Type.CITY_DROP_FLUSH_TIME.getCode()){
            if (timeSubType == null){
                LogUtils.error("CityDropGroupConfig check timeSubType null -> id:" + id );
                return false;
            }

            if (!timeSubType.check()){
                LogUtils.error("CityDropGroupConfig check subType error -> id:" + id + " timeSubType:" + timeSubType);
                return false;
            }
            if (locateType != E_CityDropPower_Type.E_CITY_DROP_POWER_ALL.getCode()){
                LogUtils.error("CityDropGroupConfig check locateType error -> id:" + id + " type:" + type + " locateType:" + locateType);
                return false;
            }
            if (visibleType != E_CityDropBelong_Status.CITY_DROP_ALL.getCode()){
                LogUtils.error("CityDropGroupConfig check visibleType error -> id:" + id + " type:" + type + " visibleType:" + visibleType);
                return false;
            }

//            if (type == E_CityDrop_Flush_Type.CITY_DROP_FLUSH_ACTIVITY.getCode()){
//                if (subtype == null || subtype.length < 3){
//                    LogUtils.error("CityDropGroupConfig check subType error -> id:" + id + " type:" + type + " subType.length:" + subtype.length);
//                    return false;
//                }
//            }
//            if (type == E_CityDrop_Flush_Type.CITY_DROP_FLUSH_EVERYWEEK.getCode()){
//                if (subtype == null || subtype.length < 2){
//                    LogUtils.error("CityDropGroupConfig check subType error -> id:" + id +" type:" + type + " subType.lenth:" + subtype.length);
//                    return false;
//                }
//            }
        }

        if (CityDropConfig.getCityDropListByGroup(rewardGroupId).isEmpty()){
            LogUtils.error("CityDropGroupConfig check rewardGroupId don't error exist this group -> id:" + id + "rewardGroupId:" + rewardGroupId);
            return false;
        }
        return true;
    }

    @Override
    public boolean setVariable(String key, String value) {
        if ("subtype".equals(key)){
            if (id >= 100){
                timeSubType = LoadUtils.loadTimeData(key,value);
            }else{
                killSubType = Integer.valueOf(value);
            }
            return true;
        }else
            return super.setVariable(key, value);
    }
}
